package com.jqr.activity.school.http;

import android.util.Log;

import androidx.annotation.NonNull;

import com.jqr.activity.school.models.Login;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import dagger.hilt.InstallIn;
import dagger.hilt.android.components.ActivityComponent;
import dagger.hilt.android.internal.managers.ApplicationComponentManager;
import io.reactivex.rxjava3.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

@InstallIn(ActivityComponent.class)
@Module
public class NetWorld {

    @Provides
    OkHttpClient providerHttpClient(){
        HttpLoggingInterceptor interceptor=new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
            @Override
            public void log(@NonNull String s) {
                Log.i("TAG",s);
            }
        });

        return  new OkHttpClient.Builder()
                .addInterceptor(interceptor)
                .build();
    }
    @Provides
    Retrofit providerRetrofit(OkHttpClient client){

      return   new Retrofit.Builder()
                .baseUrl("http://10.0.2.2:8080/")
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava3CallAdapterFactory.createWithScheduler(Schedulers.io()))
                .build();

    }

    @Provides
    JqrService providerJqrService(Retrofit retrofit){
        return  retrofit.create(JqrService.class);
    }



}
